package com.kirayous.blog.controller;


import com.kirayous.api.blog.service.ITagService;
import com.kirayous.common.Result;
import com.kirayous.common.annotation.OptLog;
import com.kirayous.common.annotation.PagePathPatternsAno;
import com.kirayous.common.constant.OptTypeConst;
import com.kirayous.common.dto.TagDTO;
import com.kirayous.common.vo.ConditionVO;
import com.kirayous.common.vo.TagVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author KiraYous
 * @since 2021-09-23
 */
@RestController
//@RequestMapping("/tag")
public class TagController {




    @Autowired
    ITagService tagService;
    /**
     * 搜索文章标签
     *
     * @param condition 条件
     * @return 标签列表
     */
    @ApiOperation(value = "搜索文章标签")
    @GetMapping("/admin/tags/search")
    public Result listTagsBySearch(ConditionVO condition) {
        return Result.success(tagService.listTagsBySearch(condition));
    }

    /**
     * 查询后台标签列表
     *
     * @param condition 条件
     * @return  标签列表
     */
    @ApiOperation(value = "查询后台标签列表")
    @GetMapping("/admin/tags")
    @PagePathPatternsAno(path = "/admin/tags")
    public Result listTagBackDTO(ConditionVO condition) {
        return Result.success(tagService.listTagBackDTO(condition));
    }

    /**
     * 删除标签
     *
     * @param tagIdList 标签id列表
     * @return {@link Result<>}
     */
    @OptLog(optType = OptTypeConst.REMOVE)
    @ApiOperation(value = "删除标签")
    @DeleteMapping("/admin/tags")
    public Result deleteTag(@RequestBody List<Integer> tagIdList) {
        tagService.deleteTag(tagIdList);
        return Result.success();
    }


    /**
     * 添加或修改标签
     *
     * @param tagVO 标签信息
     * @return {@link Result<>}
     */
    @OptLog(optType = OptTypeConst.SAVE_OR_UPDATE)
    @ApiOperation(value = "添加或修改标签")
    @PostMapping("/admin/tags")
    public Result saveOrUpdateTag(@Valid @RequestBody TagVO tagVO) {
        tagService.saveOrUpdateTag(tagVO);
        return Result.success();
    }




}

